<template>
  <div class="container">
    <div class="content">
      <div class="score_item">
        <text class="score_item_label">得分进度</text>
        <div class="progress">
          <van-progress
              stroke-width="10px"
              :percentage="getIntStr(totalStu,totalNum)"
              color="#19B300"
              track-color="#e2e2e2"
          />
        </div>
        <div class="score_item_value">
          <text :class="{'color_green':totalStu>0}">{{ totalStu }}</text>
          <text>/{{ totalNum }}</text>
        </div>
      </div>
      <div class="score_item">
        <text class="score_item_label">必修学分</text>
        <div class="progress">
          <van-progress
              stroke-width="10px"
              :percentage="getIntStr(creditData.compulsoryCreditStu,creditData.compulsoryCredit)"
              color="#ff4d03"
              track-color="#e2e2e2"
          />
        </div>
        <div class="score_item_value">
          <text :class="{'color_aqua':creditData.compulsoryCreditStu>0}">{{ creditData.compulsoryCreditStu }}</text>
          <text>/{{ creditData.compulsoryCredit ? creditData.compulsoryCredit:0}}</text>
        </div>
      </div>
      <div class="score_item">
        <text class="score_item_label">选修学分</text>
        <div class="progress">
          <van-progress
              stroke-width="10px"
              :percentage="getIntStr(creditData.optionalCreditStu,creditData.optionalCredit)"
              color="#2CACFF"
              track-color="#e2e2e2"
          />
        </div>
        <div class="score_item_value">
          <text :class="{'color_blue':creditData.optionalCreditStu>0}">{{ creditData.optionalCreditStu }}</text>
          <text>/{{ creditData.optionalCredit?creditData.optionalCredit:0 }}</text>
        </div>
      </div>
      <div class="score_item">
        <text class="score_item_label">考证学分</text>
        <div class="progress">
          <van-progress
              stroke-width="10px"
              :percentage="getIntStr(creditData.competitionCreditStu,creditData.competitionCredit)"
              color="#9649E4"
              track-color="#e2e2e2"
          />
        </div>
        <div class="score_item_value">
          <text :class="{'color_purple':creditData.competitionCreditStu>0}">{{ creditData.competitionCreditStu }}</text>
          <text>/{{ creditData.competitionCredit?creditData.competitionCredit:0 }}</text>
        </div>
      </div>
      <div class="score_item">
        <text class="score_item_label">工学学分</text>
        <div class="progress">
          <van-progress
              stroke-width="10px"
              :percentage="getIntStr(creditData.engineeringCreditStu,creditData.engineeringCredit)"
              color="#FEAD22"
              track-color="#e2e2e2"
          />
        </div>
        <div class="score_item_value">
          <text :class="{'color_orange':creditData.engineeringCreditStu>0}">{{ creditData.engineeringCreditStu }}</text>
          <text>/{{ creditData.engineeringCredit? creditData.engineeringCredit:0}}</text>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {getStudentCredit} from "../../common/api/mine";
export default {
  name: "myScore",
  data() {
    return {
      creditData:{},
      totalStu:0,
      totalNum:0,
    }
  },
  onShow() {

  },
  onLoad(option) {
    this.getStudentCredit()
  },
  methods: {
    getIntStr(num,unm2){
      return (num/unm2).toFixed(1)*100
    },
    async getStudentCredit(){
      uni.showLoading({ title: "加载中" });
      let res=await getStudentCredit()
      const {code,data}=res
      if(code==200){
        this.creditData=data
        this.totalNum=data.engineeringCredit+data.competitionCredit+data.optionalCredit+data.compulsoryCredit
        this.totalStu=data.engineeringCreditStu+data.competitionCreditStu+data.optionalCreditStu+data.compulsoryCreditStu
      }
    },
  }
}
</script>

<style scoped lang="scss">
.container{
  width: 750rpx;
  min-height: 100vh;
  background: #fafafa;
  padding: 56rpx 32rpx;
  box-sizing: border-box;
  .content{
    width: 100%;
    height: 598rpx;
    background: #FFFFFF;
    border-radius: 32rpx;
    padding: 40rpx 20rpx;
    box-sizing: border-box;
    .score_item{
      height: 77rpx;
      background: #F5F6F7;
      border-radius: 16rpx;
      padding: 16rpx 14rpx 16rpx 32rpx;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      margin-bottom: 34rpx;
      .score_item_label{
        width: 112rpx;
        font-size: 28rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
      }
      .progress{
        width: 336rpx;
        margin: 0 24rpx;
      }
      .score_item_value{
        display: flex;
        align-items: center;
        font-size: 28rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
      }
    }
    .score_item:last-child{
      margin-bottom: 0;
    }
  }
}
.color_green{
  color: #19B300!important;
}
.color_aqua{
  color: #ff4d03!important;
}
.color_blue{
  color: #2CACFF!important;
}
.color_purple{
  color: #9649E4!important;
}
.color_orange{
  color: #FEAD22!important;
}
</style>
